#pragma once

/*
 * Connection manager map
 */

#include <map>
#include "type.h"
#include "connection.hpp"

namespace KCP {
	class CConnection;
	class CConnectionMgr;

	class CConnectionMap : asio::noncopyable {
	public:
		CConnectionMap();
		virtual ~CConnectionMap();
		typedef std::map<uint32, CConnection*> ConnectionMap;

	public:
		// find from conv id.
		CConnection*  FindConnection(uint32 conv);

		// update kcp.
		void          Update(int64 clockTime);

		// clear all.
		void          Stop();
		void          Remove(uint32 conv);

		// create connect
		CConnection*  Create(CConnectionMgr& manager, uint32 conv, const udp::endpoint& endpoint);
		bool          CheckConnect(const udp::endpoint& ep) const;

		// Global get conv id.
		static uint32 GetNextConv();
		size_t        AllCount() const { return m_connections.size(); }

	private:
		ConnectionMap    m_connections;
	};
}